package com.edu.dk.cas.client.session;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import org.jasig.cas.client.session.SessionMappingStorage;

public final class SingleSignOutClusterHttpSessionListener implements HttpSessionListener {
	private SessionMappingStorage sessionMappingStorage;

	public void sessionCreated(HttpSessionEvent event) {
	}

	public void sessionDestroyed(HttpSessionEvent event) {
		if (this.sessionMappingStorage == null) {
			this.sessionMappingStorage = getSessionMappingStorage();
		}
		HttpSession session = event.getSession();
		this.sessionMappingStorage.removeBySessionById(session.getId());
	}

	protected static SessionMappingStorage getSessionMappingStorage() {
		return SingleSignOutClusterFilter.getSingleSignOutHandler().getSessionMappingStorage();
	}
}
